package com.asia.app.csv;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;


/**
 * CSV����(�����͵���)
 * 
 * @author �ּ���
 * @version 1.0 Jan 27, 2014 4:17:02 PM
 */
public class CsvTest {

    /**
     * CSV����
     * 
     * @throws Exception
     */
    public void exportCsv() {
        List<String> dataList=new ArrayList<String>();
        dataList.add("1,����,��");
        dataList.add("2,����,��");
        dataList.add("3,С��,Ů");
        boolean isSuccess=CSVUtils.exportCsv(new File("D:/test/ljq.csv"), dataList);
        System.out.println(isSuccess);
    }
    
    /**
     * CSV����
     * 
     * @throws Exception
     */
    public void importCsv()  {
        List<String> dataList=CSVUtils.importCsv(new File("D:/test/ODS����ֵ�.csv"));
        if(dataList!=null && !dataList.isEmpty()){
            for(String data : dataList){
                System.out.println(data);
            }
        }
    }
    
    public static void main(String[] args) throws IOException 
    {
    	CsvTest csvTest = new CsvTest();
 //   	csvTest.importCsv();
    	csvTest.readCSV();
    	
    }
    private static void readCSV() throws IOException 
    {
    	int num = 0;
    	String tableSpecification = null;
        File[] files = new File("D:\\test").listFiles();//��Ŀ¼��ȡ�ļ�
        BufferedReader br = null;
        try {
            for (File file : files) 
            {//���������ļ�
                if (!file.isFile()) 
                {//������ļ������
                    continue;
                }
                br = new BufferedReader(new InputStreamReader(new FileInputStream(file)));//����ļ���
                String line = null;
                while ((line = br.readLine()) != null) 
                {//��ȡһ��
                    String[] parts = line.split(",");
                    if (1==parts.length) 
                    {
                    	System.out.print("��ͷ");
                    	tableSpecification = parts[0];
					}
                    
 //                   StringBuilder b = new StringBuilder();
 //                   b.append("insert into myTable(id,name,address,phone) values (");
                    for (num=0;num<parts.length;num++) 
                    {
 //                     b.append("'" + s + "',");

                    	System.out.println(parts[num].toUpperCase());

                    	
                    }
 //                   b.deleteCharAt(b.length() - 1);
  //                  parts[1].toUpperCase();
 //                   b.append(")");
 //                   String sql = b.toString();
                    System.out.println("***************************");
                }
            }
        } finally {
            if (br != null) {
                br.close();
            }
        }
    }
}